function map = jcb_colormap(m,palette)
%JCB_COLORMAP    various colormaps
%   JCB_COLORMAP(M) returns an M-by-3 matrix containing a colormap.
%   JCB_COLORMAP, by itself, is the same length as the current figure's
%   colormap. If no figure exists, MATLAB creates one.
%
%   JCB_COLORMAP(M,PALETTE) returns an M-by-3 matrix containing a colormap
%   corresponding to the index PALETTE. Possible colormaps according to index 
%   are:
%     1 - scales lightness, ranging from black, through red to almost white
%     2 - scales lightness, ranging from black, through green to almost
%         white
%     3 - scales lightness, ranging from black, through blue to almost
%         white
%     4 - scales hue, but not over its whole range. Ranges from blueish
%         through to red
%     5 - mainly scales lightness, but also alters hue, ranging from black,
%         through orange, to yellow-white
%     6 - an extended version of jet, scales lightness, then hue, then
%         lightness again. Ranges from black, through to blue, through hue
%         to red, then lighter to almost white
%
%   For example, to reset the colormap of the current figure:
%             colormap(jcb_colormap)
%
%   See also HSV, GRAY, HOT, COOL, BONE, COPPER, PINK, FLAG, PRISM, JET,
%   COLORMAP, RGBPLOT, HSV2RGB, RGB2HSV, HSL2RGB, RGB2HSL.

    if nargin<2
        palette=1;
        if nargin<1
            m=[];
        end
    end
    if isempty(m)
        m=size(get(gcf,'colormap'),1);
    end
    palette=mod(palette-1,7)+1;
    
    cursor=linspace(0,1,m)';
    S=1*ones(size(cursor));
    L=0.5*ones(size(cursor));
    H=0*ones(size(cursor));
    switch palette
        case 1
            H = 0*ones(size(cursor));
            L=cursor;
            L(L>0.9)=0.9;
        case 2
            H = 85/255*ones(size(cursor));
            L=cursor;
            L(L>0.9)=0.9;
        case 3
            H = 170/255*ones(size(cursor));
            L=cursor;
            L(L>0.9)=0.9;
        case 4
            H = 2/3*(1-cursor);
            L = 0.5*ones(size(cursor));
        case 5
            H = 0.2*cursor;
            L=cursor;
            L(L>0.9)=0.9;
        case 6
            H = rand*ones(size(H));
            L=cursor;
            L(L>0.9)=0.9;
        case 7
            [H S L] = rgb2hsl(jet(m));
            s=floor(m/8);
            L(1:s)=linspace(0.15,0.5,s);
            %L(end-s+1:end)=linspace(0.5,0.3,s);
            %H(1:s)=2/3;
            %H(end-s+1:end)=0;
            %H(s+1:end-s)=linspace(2/3,0,m-2*s);
    end
    map=hsl2rgb([H S L]);
    map(map<0)=0;
    map(map>1)=1;